package com.ddz.qpz.service.impl;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ddz.qpz.listener.ExcelCityDTOListener;
import com.ddz.qpz.listener.ExcelDictDTOListener;
import com.ddz.qpz.mapper.CityMapper;
import com.ddz.qpz.pojo.dto.ExcelCityDTO;
import com.ddz.qpz.pojo.dto.ExcelDictDTO;
import com.ddz.qpz.pojo.entity.City;
import com.ddz.qpz.service.CityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.InputStream;

/**
 * @Author: LiQingBo
 * @Date: 2021/11/7-11-07-11:53
 * @Description: com.ddz.qpz.service.impl
 * @version: 1.0
 */
@Service
@Slf4j
public class CityServiceImpl extends ServiceImpl<CityMapper, City> implements CityService {
    @Transactional(rollbackFor = {Exception.class})
    @Override
    public void importData(InputStream inputStream) {
        EasyExcel.read(inputStream, ExcelCityDTO.class, new ExcelCityDTOListener(baseMapper)).sheet().doRead();
        log.info("Excel导入成功");
    }
}
